package com.homedo.async.mysql.support.prepare;

import com.homedo.async.common.dto.Pagination;
import com.homedo.async.mysql.support.dml.DMLEnum;
import com.homedo.async.mysql.support.meta.EntityMetaData;
import com.homedo.async.mysql.support.prepare.delete.Records2Sql4Delete;
import com.homedo.async.mysql.support.prepare.insert.Records2Sql4Insert;
import com.homedo.async.mysql.support.prepare.select.Records2Sql4Select;
import com.homedo.async.mysql.support.prepare.update.Records2Sql4Update;
import lombok.Data;

/**
 * @author jgshun
 * @date 2020/3/5 1:56 PM
 */
@Data
public class PrepareRecords2Sql<T> {

    private Iterable<T> records;
    private EntityMetaData<T> entityMetaData;
    private DMLEnum dml;
    private boolean includeNullVals;

    private Pagination<T> pagination;

    public PrepareRecords2Sql() {
    }

    public PrepareRecords2Sql(EntityMetaData<T> entityMetaData, DMLEnum dml, Iterable<T> records, boolean includeNullVals) {
        this.records = records;
        this.entityMetaData = entityMetaData;
        this.dml = dml;
        this.includeNullVals = includeNullVals;
    }

    public Object[] prepare() {
        if (this.dml == DMLEnum.SELECT) {
            return Records2Sql4Select.prepare(this.entityMetaData, this.records, this.includeNullVals, this.pagination);
        } else if (this.dml == DMLEnum.DELETE) {
            return Records2Sql4Delete.prepare(this.entityMetaData, this.records, this.includeNullVals);
        } else if (this.dml == DMLEnum.INSERT) {
            return Records2Sql4Insert.prepare(this.entityMetaData, this.records, this.includeNullVals);
        } else if (this.dml == DMLEnum.UPDATE) {
            return Records2Sql4Update.prepare(this.entityMetaData, this.records, this.includeNullVals);
        } else {
            //TODO
        }

        return new Object[0];
    }

}

